package com.example.liulongjin;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatTextView;

import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

public class DetailActivity extends AppCompatActivity {

    private AppCompatTextView ipTextView;
    private AppCompatTextView contentTextView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //实例化控件
        setContentView(R.layout.activity_detail);
        ipTextView = findViewById(R.id.ipTextView);
        contentTextView = findViewById(R.id.contentTextView);
        //初始化数据
        String ip = getIntent().getStringExtra("ip");
        ipTextView.setText(ip);
        OkGo.<String>get("http://whois.pconline.com.cn/ipJson.jsp?ip=" + ip + "&json=true").execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                IpBean ipBean = new Gson().fromJson(response.body(), IpBean.class);
                contentTextView.setText("省份："+ipBean.getPro()+"\n");
                contentTextView.append("省份编码："+ipBean.getProCode()+"\n");
                contentTextView.append("城市："+ipBean.getCity()+"\n");
                contentTextView.append("城市编码："+ipBean.getCityCode()+"\n");
                contentTextView.append("地址："+ipBean.getAddr()+"\n");
            }
        });
    }

}
